#准确度
# from pandas import read_csv
# from sklearn.model_selection import ShuffleSplit
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import cross_val_score
# filename = 'pima_data.csv'
# names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
# data = read_csv(filename, names=names)
# array = data.values
# X = array[:, 0:8]
# Y = array[:, 8]
# n_splits = 10
# test_size = 0.33
# seed = 7
# kfold = ShuffleSplit(n_splits=n_splits, test_size=test_size, random_state=seed)
# model = LogisticRegression(multi_class='multinomial', max_iter=1100)
# result = cross_val_score(model, X, Y, cv=kfold)
# print("算法评估：%.3f%% (%.3f%%)" % (result.mean()*100, result.std()*100))

#对数损失函数
# from pandas import read_csv
# from sklearn.model_selection import KFold
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import cross_val_score
# filename = 'pima_data.csv'
# names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
# data = read_csv(filename, names=names)
# array = data.values
# X = array[:, 0:8]
# Y = array[:, 8]
# num_flods = 10
# seed = 7
# kfold = KFold(n_splits=num_flods, random_state=seed, shuffle=True)
# model = LogisticRegression(multi_class='multinomial', max_iter=1100)
# Scoring = 'neg_log_loss'
# result = cross_val_score(model, X, Y, cv=kfold, scoring=Scoring)
# print('LogLoss: %.3f (%.3f) ' % (result.mean(), result.std()))

#AUC图
# from pandas import read_csv
# from sklearn.model_selection import KFold
# from sklearn.linear_model import LogisticRegression
# from sklearn.model_selection import cross_val_score
# filename = 'pima_data.csv'
# names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
# data = read_csv(filename, names=names)
# array = data.values
# X = array[:, 0:8]
# Y = array[:, 8]
# num_flods = 10
# seed = 7
# kfold = KFold(n_splits=num_flods, random_state=seed, shuffle=True)
# model = LogisticRegression(multi_class='multinomial', max_iter=1100)
# scoring = 'roc_auc'
# result = cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
# print('AUC %.3f (%.3f)' %(result.mean(), result.std()))
#混淆矩阵
# from pandas import read_csv
# import pandas as pd
# from sklearn.model_selection import train_test_split
# from sklearn.linear_model import LogisticRegression
# from sklearn.metrics import confusion_matrix
# filename = 'pima_data.csv'
# names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
# data = read_csv(filename, names=names)
# array = data.values
# X = array[:, 0:8]
# Y = array[:, 8]
# test_size = 0.33
# seed = 4
# X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)
# model = LogisticRegression(multi_class='multinomial', max_iter=1100)
# model.fit(X_train, Y_train)
# predicted = model.predict(X_test)
# matrix = confusion_matrix(Y_test, predicted)
# classes = ['0', '1']
# dataframe = pd.DataFrame(data=matrix, index=classes, columns=classes)
# print(dataframe)
#结果报告
# from pandas import read_csv
# import pandas as pd
# from sklearn.model_selection import train_test_split
# from sklearn.linear_model import LogisticRegression
# from sklearn.metrics import classification_report
# filename = 'pima_data.csv'
# names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'pedi', 'age', 'class']
# data = read_csv(filename, names=names)
# array = data.values
# X = array[:, 0:8]
# Y = array[:, 8]
# test_size = 0.33
# seed = 4
# X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=test_size, random_state=seed)
# model = LogisticRegression(multi_class='multinomial', max_iter=1100)
# model.fit(X_train, Y_train)
# predicted = model.predict(X_test)
# report = classification_report(Y_test, predicted)
# print(report)

from pandas import read_csv
from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.linear_model import LinearRegression
filename = 'housing.csv'
names = ['CRIM', 'ZN', 'INDUS', 'CHAS', 'NOX', 'RM', 'AGE', 'DIS',
         'RAD', 'TAX', 'PRTATIO', 'B', 'LSTAT', 'MEDV']

data = read_csv(filename, names=names, delim_whitespace=True)#上课讲解中忘记分割数据，这个数据并不是标准的分割好的，所以这一步需要分割数据
array = data.values
X = array[:, 0:13]
Y = array[:, 13]
num_fold = 10
seed = 7
kfold = KFold(n_splits=num_fold, random_state=seed, shuffle=True)
model = LinearRegression()
scoring = 'neg_mean_absolute_error'
result = cross_val_score(model, X, Y, cv=kfold, scoring=scoring)
print('MAE: %.3f (%.3f)' %(result.mean(), result.std()))
